import datetime
import os.path
import sys
import time

from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from selenium.webdriver.edge.service import Service as EdgeService
driver_path = '../msedgedriver.exe'

class Driver:
    driver=''
    def __init__(self):
        # self.driver=webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))
        self.driver=webdriver.Edge(service=EdgeService(executable_path=driver_path))

        # 隐式等待
        self.driver.implicitly_wait(3)

    def getScreenShot(self):
        dirname=datetime.datetime.now().strftime("%Y-%m-%d")
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)
        filename=datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")
        # 能知道调用本接口的接口名
        funcname = sys._getframe().f_back.f_code.co_name + "-"
        # 目标：../images/2025-3-14/接口名-2025-3-14-202101.png
        self.driver.save_screenshot("../images/"+dirname+"/"+funcname+filename+".png")

# 创建driver对象
ForumDriver=Driver()






